﻿<Window x:Class="BookManager.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:vw="clr-namespace:BookManager.Views"
        xmlns:vm="clr-namespace:BookManager.ViewModels"
        xmlns:conv="clr-namespace:CommonUtilities.Converters;assembly=CommonUtilities"
        xmlns:ctrl="clr-namespace:BookManager.Views.Controls"
        xmlns:cutilctrl="clr-namespace:CommonUtilities.Controls;assembly=CommonUtilities"
        xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
        Title="MainWindow" MinHeight="600" Width="961" x:Name="this"
        WindowStartupLocation="CenterScreen" WindowState="Maximized"
        Icon="/BookManager;component/Images/bookmgr_stacked_colour.ico">
    <Window.Resources>
        <conv:VisibilityConverter x:Key="VisibilityConverter" />
    </Window.Resources>

    <Border Name="brdMainLayout" Margin="5" Padding="5" BorderThickness="2" CornerRadius="5">
        <Border.BorderBrush>
            <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
                <GradientStop Color="Gray" Offset="0" />
                <GradientStop Color="White" Offset="1" />
            </LinearGradientBrush>
        </Border.BorderBrush>
        <Border.Background>
            <LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5">
                <GradientStop Color="#FFDCDCDC" Offset="0" />
                <GradientStop Color="#FFF2F2F2" Offset="0.5" />
                <GradientStop Color="White" Offset="1" />
            </LinearGradientBrush>
        </Border.Background>

        <Grid Name="MainLayout">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>

            <StackPanel Name="stkLogoTitle" Grid.ColumnSpan="2" HorizontalAlignment="Stretch" Orientation="Horizontal">
                <Image Name="imgLogo" Height="80" Width="80" 
                        HorizontalAlignment="Left" VerticalAlignment="Top"
                        Source="/BookManager;component/Images/bookmgr_stacked_button.png" />
                <TextBlock Name="txtbAppName" Grid.Column="1" Margin="10,5"
                            FontFamily="Calibri" FontWeight="Bold" FontSize="60" Text="Book Manager" />
            </StackPanel>

            <StackPanel Grid.Column="1" Grid.ColumnSpan="2" HorizontalAlignment="Right" VerticalAlignment="Top" Orientation="Horizontal">
                <Border Name="brdSearch" Margin="1,0" Height="23" BorderBrush="Brown" BorderThickness="1" CornerRadius="5" Background="White">
                    <StackPanel Name="stkSearch" Orientation="Horizontal">
                        <ToggleButton Name="tglSearch" Margin="-1,0,0,0" Width="25" BorderBrush="Transparent"
                                        IsChecked="{Binding DisplaySearchBox}"
                                        Visibility="{Binding DisplaySearchBox, Converter={StaticResource VisibilityConverter}, ConverterParameter=-}">
                            <ToggleButton.Template>
                                <ControlTemplate TargetType="ToggleButton">
                                    <ContentPresenter>
                                        <ContentPresenter.Content>
                                            <Image Name="imgSearch" Height="18" Width="18" Source="/BookManager;component/Images/bookmgr_searchglass.png" />
                                        </ContentPresenter.Content>
                                    </ContentPresenter>
                                </ControlTemplate>
                            </ToggleButton.Template>
                        </ToggleButton>
                        <Grid Name="grdSearchBox" Height="Auto" Visibility="{Binding DisplaySearchBox, Converter={StaticResource VisibilityConverter}}">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition />
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>

                            <cutilctrl:CUtil_WatermarkTextBox Name="txtSearchBox" Margin="1,0,-3,1" Width="250" Padding="3,0,3,0" 
                                                              BorderBrush="Brown" BorderThickness="0"
                                                              VerticalAlignment="Stretch" VerticalContentAlignment="Center"
                                                              Text="{Binding SearchText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                                              vm:FocusExtension.IsFocused="{Binding IsSearchBoxFocused}"
                                                              WatermarkText="Search here.." WatermarkForeground="LightGray" WatermarkAlignment="Left"
                                                              KeyDown="txtSearchBox_KeyDown">
                                <i:Interaction.Triggers>
                                    <i:EventTrigger EventName="LostFocus">
                                        <i:InvokeCommandAction Command="{Binding SearchBoxLostFocusCommand}" CommandParameter="{Binding SearchText}" />
                                    </i:EventTrigger>
                                </i:Interaction.Triggers>
                            </cutilctrl:CUtil_WatermarkTextBox>
                            <Button Name="btnClearSearchBox" Grid.Column="1" Margin="3,0" HorizontalAlignment="Center" VerticalAlignment="Center"
                                    Width="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=ActualHeight}" Visibility="{Binding ClearSearchVisibility}"
                                    Command="{Binding ClearSearchTextCommand}" CommandParameter="{Binding SearchText}">
                                <Button.Template>
                                    <ControlTemplate TargetType="Button">
                                        <ContentPresenter>
                                            <ContentPresenter.Content>
                                                <TextBlock Margin="0,2" HorizontalAlignment="Center" VerticalAlignment="Center" Text=" X " 
                                                            FontFamily="Berlin Sans FB" FontSize="10" FontWeight="Normal" Foreground="White" Background="Red" />
                                            </ContentPresenter.Content>
                                        </ContentPresenter>
                                    </ControlTemplate>
                                </Button.Template>
                            </Button>
                            <Rectangle Grid.Column="2" Width="0.5" HorizontalAlignment="Right" VerticalAlignment="Stretch" Fill="LightGray" />
                        </Grid>
                        <Button Name="btnSearchBook" Margin="0,0,-1,0" Width="25" 
                                Visibility="{Binding DisplaySearchBox, Converter={StaticResource VisibilityConverter}}"
                                Command="{Binding SearchBookCommand}" CommandParameter="{Binding SearchText}">
                            <Button.Template>
                                <ControlTemplate TargetType="Button">
                                    <ContentPresenter>
                                        <ContentPresenter.Content>
                                            <Image Name="imgSearchBook" Height="18" Width="18" Source="/BookManager;component/Images/bookmgr_searchglass.png" />
                                        </ContentPresenter.Content>
                                    </ContentPresenter>
                                </ControlTemplate>
                            </Button.Template>
                        </Button>
                    </StackPanel>
                </Border>
                <Button Name="btnStatistics" Margin="1,0" Width="23" Command="{Binding OpenStatsCommand}">
                    <Image Name="imgStatistics" Margin="-5" Source="/BookManager;component/Images/bookmgr_stats.png" />
                </Button>
                <Button Name="btnSettings" Margin="1,0,0,0" Width="23" Command="{Binding OpenSettingsCommand}">
                    <!--<Button.Template>
                        <ControlTemplate TargetType="Button">
                            <Border BorderBrush="Brown" BorderThickness="1" CornerRadius="5">
                                <ContentPresenter>
                                    <ContentPresenter.Content>-->
                    <Image Name="imgSettings" Height="18" Width="18" HorizontalAlignment="Center" Source="/BookManager;component/Images/bookmgr_settings.png" />
                    <!--</ContentPresenter.Content>
                                </ContentPresenter>
                            </Border>
                        </ControlTemplate>
                    </Button.Template>-->
                </Button>
            </StackPanel>

            <Border Name="brdResults" Grid.Row="1" Grid.ColumnSpan="3" Padding="5" BorderThickness="1" CornerRadius="5">
                <Border.BorderBrush>
                    <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
                        <GradientStop Color="Gray" Offset="0" />
                        <GradientStop Color="White" Offset="1" />
                    </LinearGradientBrush>
                </Border.BorderBrush>

                <Grid Name="grdResults">
                    <TextBlock Name="txtbNoResults" HorizontalAlignment="Center" VerticalAlignment="Center" Opacity="0.5" 
                               Visibility="{Binding HasResults, Converter={StaticResource VisibilityConverter}, ConverterParameter=-}"
                               Text="{Binding MySettings.NoResultText}" TextAlignment="Justify" TextWrapping="Wrap" FontSize="15" FontFamily="Calibri">
                        <TextBlock.Foreground>
                            <LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5">
                                <GradientStop Color="LightGray" Offset="-0.5" />
                                <GradientStop Color="Gray" Offset="0" />
                                <GradientStop Color="Black" Offset="0.5" />
                            </LinearGradientBrush>
                        </TextBlock.Foreground>
                    </TextBlock>

                    <Grid Name="grdBookSearchResultLayout" Visibility="{Binding HasResults, Converter={StaticResource VisibilityConverter}}">
                        <Grid Name="grdBookSearchResult" Visibility="{Binding DisplayDetails, Converter={StaticResource VisibilityConverter}, ConverterParameter=-}" >
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition />
                            </Grid.ColumnDefinitions>

                            <ScrollViewer Name="scrlBookList" MinWidth="350" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Visible">
                                <ItemsControl Name="itmctrlBookList" ItemsSource="{Binding AllFilteredBooks}">
                                    <ScrollBarVisibility />
                                    <ItemsControl.ItemsPanel>
                                        <ItemsPanelTemplate>
                                            <UniformGrid VerticalAlignment="Top" Columns="2" />
                                        </ItemsPanelTemplate>
                                    </ItemsControl.ItemsPanel>
                                    <ItemsControl.ItemTemplate>
                                        <DataTemplate>
                                            <ctrl:BookListItem x:Name="uctlBookListItem" />
                                        </DataTemplate>
                                    </ItemsControl.ItemTemplate>
                                </ItemsControl>
                            </ScrollViewer>

                            <ScrollViewer Name="scrlBookShelf" Grid.Column="1" HorizontalContentAlignment="Center" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Visible" SizeChanged="scrlBookShelf_SizeChanged">
                                <ItemsControl Name="itmctrlBookShelf" HorizontalAlignment="Stretch" HorizontalContentAlignment="Center" ItemsSource="{Binding AllFilteredBooks}">
                                    <ScrollBarVisibility />
                                    <ItemsControl.ItemTemplate>
                                        <DataTemplate>
                                            <ctrl:BookShelfItem x:Name="uctlBookShelfItem" />
                                        </DataTemplate>
                                    </ItemsControl.ItemTemplate>
                                </ItemsControl>
                            </ScrollViewer>
                        </Grid>

                        <vw:BookDetailsWindow HorizontalAlignment="Stretch" VerticalAlignment="Stretch" 
                                              Visibility="{Binding DisplayDetails, Converter={StaticResource VisibilityConverter}}" />
                    </Grid>
                </Grid>
            </Border>
        </Grid>
    </Border>
</Window>
